package logic

import (
	"context"

	"storage/internal/svc"
	"storage/pb/storage"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetFolderByIDsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetFolderByIDsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFolderByIDsLogic {
	return &GetFolderByIDsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetFolderByIDs 获取文件夹列表
func (l *GetFolderByIDsLogic) GetFolderByIDs(in *storage.IDListRequest) (*storage.FolderListResponse, error) {
	list, err := l.svcCtx.StorageModel.GetFolderByIDs(l.ctx, in.Ids)
	if err != nil {
		return nil, err
	}
	var folderList []*storage.FolderInfo
	for _, folder := range list {
		folderList = append(folderList, &storage.FolderInfo{
			Id:         folder.Id,
			UserId:     folder.UserId,
			ParentId:   folder.ParentId,
			FolderName: folder.FolderName,
			Status:     folder.Status,
			CreateAt:   folder.CreateAt.Unix(),
			UpdateAt:   folder.UpdateAt.Unix(),
		})
	}
	return &storage.FolderListResponse{List: folderList}, nil
}
